# Simple demo, can be used to verify proper Mk4py installation

import Mk4py, sys
mk = Mk4py
print sys.argv[0], '- Mk4py', mk.version, '-', sys.platform

# On first run, output should consist of 5 lines:
#   John Lennon 44
#   Flash Gordon 42
#   Flash Gordon 42
#   John Lennon 44
#   John Lennon 44
# Each following run will generate 5 more lines of output

  # create a file called "demo.db"
db = mk.storage("demo2.db",1)
  # define a view in it called "people", containing three fields
vw = db.getas("td[first:I,last:S,shoesize:I]")

for _i in range ( 1000000 ):
  # let's append two rows to the end of the view
  vw.append(first=_i,last='%d-%d'%(_i,_i),shoesize=_i/1000)

  # commit the structure and data to file
db.commit()

  # a simple loop to print out all rows
#for r in vw:
#  print r.first, r.last, r.shoesize

  # another way to loop, in sorted order
#for r in vw.sort(vw.last):
#  print r.first, r.last, r.shoesize

  # this loop iterates over a selection 
for r in vw.select(first=999):
  print r.first, r.last, r.shoesize
